package business.manage.system.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import common.database.interfaces.BaseDAO;

import business.manage.system.dto.Menu;

@Service
public class MenuService {

	private static String SELECT_SQL = "select id,code,name,url, parent, is_show as isShow,createby as createBy,createDate, updateBy,udpateDate from sys_menu t ";

	private static String INSERT_SQL = "insert into sys_menu(id,code,name,url,parent,is_show,createby,createDate,updateBy,udpateDate)values(:id,code,:name,:url,:parent,:is_show,:createby,:createDate,:updateBy,:udpateDate)";
	@Autowired
	private BaseDAO baseDAO;

	public List<Menu> listMenu() throws Exception{
		String listMemuSql = SELECT_SQL + "WHERE t.is_show=1";
		List<Menu> list = baseDAO.getList(listMemuSql, Menu.class);
		return list;
	}

	public int addMenu(Menu menu)throws Exception {
		int result = baseDAO.update(INSERT_SQL, menu);
		return result;
	}
}
